#region Disclaimer by Teo Lachev
/*============================================================================
  The CustomDataExtension sample uses code from the Microsoft File Share Data 
  Processing Extension Sample (http://msdn2.microsoft.com/en-us/library/ms160918.aspx). 
  The orginal code base has been modified whenever needed to re-purpose the 
  extension to support ADO.NET datasets. Most code changes are implemented in the 
  DsDataReader class.
===========================================================================*/
#endregion

using System;
using Microsoft.ReportingServices.DataProcessing;
using System.Collections;
using System.Globalization;
using System.Diagnostics;

namespace Prologika.RS.Extensibility.CustomDataExtension
{
   

    /// <summary>
    /// Represents a collection of query parameters
    /// </summary>
    /// <remarks>
        ///Because IDataParameterCollection is primarily an IList,
        ///the sample can use an existing class for most of the implementation.
        ///In this sample, we use ArrayList. 
    /// </remarks>
   public class DsDataParameterCollection : ArrayList, IDataParameterCollection
   {
		public object this[string index] 
		{

			get
		{
			return this[IndexOf(index)];
		}
			set
			{
				this[IndexOf(index)] = value;
			}
		}
		/// <summary>
		/// Helper wrapper to get a parameter by name
		/// </summary>
		/// <param name="parameterName"></param>
		/// <returns></returns>
		public DsDataParameter GetByName(string parameterName)
		{
			DsDataParameter parameter = null;
			IEnumerator enumerator = this.GetEnumerator();
			while (enumerator.MoveNext())
			{
				DsDataParameter tempParameter = (DsDataParameter) enumerator.Current;
				if (tempParameter.ParameterName == parameterName) 
				{
					parameter = tempParameter;
					break;
				}
			}
			return parameter;
		}

		public int Add(IDataParameter value)
		{
			Trace.WriteLine("DataSet Extension: Add(IDataParameter value");
			if (((DsDataParameter)value).ParameterName != null)
			{
				return base.Add(value);
			}
			else
				throw new ArgumentException("parameter must be named");
		}

 
	   public override int Add(object value)
	   {
		   Trace.WriteLine("Add value" + value.ToString());
		   return Add((IDataParameter)value);
	   }
   }
}

